<?php

namespace app\admin\model\scenic;

use think\Model;
use traits\model\SoftDelete;

class Scenic extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'scenic';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'category_id_text',
        'level_text'
    ];

    public function getLevelList()
    {
        return [1=>'1A',2=>'2A',3=>'3A',4=>'4A',5=>'5A'];
    }

    public function getLevelTextAttr($value, $data)
    {
        $value = $value ?: ($data['level'] ?? '');
        $list = $this->getLevelList();
        return $list[$value] ?? '';
    }


    public function getCategoryIdTextAttr($value, $data)
    {
        $value = $value ?: ($data['category_id'] ?? '');

        $category_list = ScenicCategory::where('id','in',$value)->column('name');
        if ($category_list){
            return implode('/',$category_list);
        } else {
            return '';
        }

    }


}
